package pzl.com.compositepattern;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-02]
 *          <p/>
 *          文件夹
 */
public class FolderComponent extends FileSystemComponent {
    static final String TAG = "FolderComponent";

    private List<FileSystemComponent> list;

    public FolderComponent(String name) {
        super(name);
        list = new ArrayList<FileSystemComponent>();
    }

    @Override
    void add(FileSystemComponent component) {
        list.add(component);
    }

    @Override
    void remove(FileSystemComponent component) {
        Log.w(TAG, "删除文件夹[" + component.getName() + "]");
        list.remove(component);
        component.delete();
    }

    @Override
    void delete() {
        for (FileSystemComponent temp : list) {
            temp.delete();
        }
        list.clear();
    }

    @Override
    void display() {
        Log.w(TAG, "文件夹:" + name);
        for (FileSystemComponent temp : list) {
            temp.display();
        }
    }

}
